const service = require("../service/loginService");
const jwt = require("../uilt/JWT");
const controller = {
  async find(cxt, next) {
    const { password, username } = cxt.request.body;
    // 去数据库查找
    let [data] = await service.find(username, password);
    console.log(data);
    if (data.length) {
      let token = jwt.generate(data[0], "1d");
      cxt.set("Authorization", token);
      cxt.body = { OK: 1 };
    } else {
      cxt.body = { OK: 0 };
    }
  },
};
module.exports = controller;
